package schedule.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @see <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html">CronSequenceGenerator</a>
 */
@Component
public class ScheduledTasks {
    private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

//    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        logger.info("The time is now {}", dateFormat.format(new Date()));
    }

//    @Scheduled(fixedDelay = 6000)
    public void reportDelayTime() {
        logger.info(" Pili is delay, now is {}", dateFormat.format(new Date()));
    }

    /**
     *
     * second, minute, hour, day of month, month and day of week
     * run every ten secs
     */
//    @Scheduled(cron = "*/10 * * * * *")
    public void workEverySecond() {
        logger.info("Ola coming at {}", dateFormat.format(new Date()));
    }

    /**
     * run at 1:00 every day
     */
//    @Scheduled(cron = "0 8 19 * * *")
    public void workEveryHour() {
        logger.info("Lele going to sleep at {}", dateFormat.format(new Date()));
    }
}
